package com.example.Controller;

import com.example.dao.UserDao;
import com.example.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {
    @Autowired
    private UserDao userDao;
    @RequestMapping("/user/register")
    public String  register(
            @RequestParam("username") String name,
            @RequestParam("password") String password,
            @RequestParam("email") String email
    ){
        int count = userDao.count()+1;
        System.out.println(count);
        User user = new User(count,name,email,password);
        System.out.println(user.toString());
        System.out.println(user.getUserName().equals(""));
        if (user.getUserName().equals("")&&user.getLoginPwd().equals("")&&user.getLoginName().equals("")) {

            System.out.println("空");
            return "register";
        }
        else {
            int insert = userDao.insertSelective(user);
            System.out.println(insert);
            System.out.println(user.toString());
            return "index";

        }
    }
}
